package com.liang.threadpool;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ThreadPoolExecutorDemo3 {
    public static void main(String[] args) {
        ThreadPoolExecutor pool= new ThreadPoolExecutor(
                1,
                2,
                2,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(1),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.DiscardOldestPolicy());

        for (int i = 1; i <= 15; i++) {
            final int y=i;
            pool.submit(()->{
                System.out.println(Thread.currentThread().getName()+"正在执行"+y);
            });

        }
        pool.shutdown();

    }
}
